package org.crud4j.validator;

import java.lang.annotation.Annotation;


public class NullableValidator implements ValueValidator {

	private boolean nullable;

	public void validate(Object value) throws ValueValidatorException {
		if (!nullable && value == null) {
			throw new ValueValidatorException("null values are not allowed");
		}
	}

	public Class<Nullable> getAnnotationClass() {
		return Nullable.class;
	}

	public void init(Annotation annotation) {
		Nullable nullable = (Nullable) annotation;
		this.nullable = nullable.value();
	}

}
